﻿using ExpenseSystem.Common;
using ExpenseSystem.Model;
using ExpenseSystem.Fether;


namespace ExpenseSystem.Core.DataAddOn
{
    public class ProductionSetRateAddOn : IAddable<ProductionModel>
    {
        public void Add(ProductionModel data)
        {
            if(data!=null)
            {
                UnitFetcher unitFetcher = new UnitFetcher();
                UnitModel baseUnit = unitFetcher.Get(data.Site,data.UnitId,out string message);
                UnitModel salesUnit = unitFetcher.Get(data.Site, data.SalesUnitId, out message);
                if(baseUnit!=null&&salesUnit!=null)
                {
                    data.Rate = (decimal)((baseUnit.Rate / baseUnit.RateBase) / (salesUnit.Rate / salesUnit.RateBase));
                }
            }
        }
    }
}
